using System;
using System.Collections.Generic;
using System.Text;

using NHibernate;
using Framework.Library.Domain;
using Framework.Library.Base;

namespace Framework.Library.DAO
{
    public partial interface IPortalUserpermisionManager : IManagerBase<PortalUserpermision, string>
    {
		// Get Methods
		PortalUserpermision GetById(System.Int32 userID, System.Int32 portalID, System.Int32 commandID);
    }

    partial class PortalUserpermisionManager : ManagerBase<PortalUserpermision, string>, IPortalUserpermisionManager
    {
		#region Constructors
		
		public PortalUserpermisionManager() : base()
        {
        }
        public PortalUserpermisionManager(INHibernateSession session) : base(session)
        {
        }
		
		#endregion
		
        #region Get Methods

		public override PortalUserpermision GetById(string id)
		{
			string[] keys = id.Split('^');
			
			if(keys.Length != 3)
				throw new Exception("Invalid Id for PortalUserpermisionManager.GetById");
			
			return GetById(System.Int32.Parse(keys[0]), System.Int32.Parse(keys[1]), System.Int32.Parse(keys[2]));
		}
		public PortalUserpermision GetById(System.Int32 userID, System.Int32 portalID, System.Int32 commandID)
		{
			ICriteria criteria = Session.GetISession().CreateCriteria(typeof(PortalUserpermision));
			
			criteria.Add(NHibernate.Criterion.Expression.Eq("UserID", userID));
			criteria.Add(NHibernate.Criterion.Expression.Eq("PortalID", portalID));
			criteria.Add(NHibernate.Criterion.Expression.Eq("CommandID", commandID));
			
			PortalUserpermision result = (PortalUserpermision)criteria.UniqueResult();

            if (result == null)
                throw new NHibernate.ObjectDeletedException("", null, null);

            return result;
		}
		
		
		#endregion
    }
}